use crate::{
    helpers::{Bot, Config},
    keyboards::standart_keyboard,
};
use anyhow::Result;
use db::{/*models::MatrixOrTelegramId,*/ Db};
use teloxide::prelude::*;
use uuid::Uuid;

pub async fn unfavorite(
    bot: Bot,
    q: CallbackQuery,
    data: &str,
    db: Db,
    _config: Config,
) -> Result<()> {
    let _user_id = q.from.id;
    // let user = MatrixOrTelegramId::TelegramId { id: user_id, username: None };
    // let user = db.get_user_id(&user).await?;
    let post_id = Uuid::parse_str(data)?;
    db.unfavorite_post(post_id).await?;
    let is_archived = db.is_read(&post_id).await?;
    let is_real = db.show_real_url(&post_id).await?;
    let message_id = q.message.clone().unwrap().id;
    let chat_id = q.message.clone().unwrap().chat.id;
    bot.answer_callback_query(q.id).text("Unfavorite!").await?;
    /*bot.edit_message_text(chat_id, message_id, text)
    .entities(q.message.clone().unwrap().entities().unwrap().to_owned())
    .await?;*/
    bot.edit_message_reply_markup(chat_id, message_id)
        .reply_markup(standart_keyboard(data, is_archived, false, is_real))
        .await?;
    Ok(())
}
